package job_types

import (
	"gitlab.ctyuncdn.cn/tai/infra/cloud-controller/internal/job_manager"
)

// RegisterAllJobTypes registers all available job type handlers with the job manager
func RegisterAllJobTypes(manager job_manager.JobManager) error {
	// Register notebook job type handler
	notebookHandler := NewNotebookJobTypeHandler()
	if err := manager.RegisterJobType(job_manager.JobTypeNotebook, notebookHandler); err != nil {
		return err
	}

	// Register training job type handler
	trainingHandler := NewTrainingJobTypeHandler()
	if err := manager.RegisterJobType(job_manager.JobTypeTraining, trainingHandler); err != nil {
		return err
	}

	// Register batch job type handler
	batchHandler := NewBatchJobTypeHandler()
	if err := manager.RegisterJobType(job_manager.JobTypeBatch, batchHandler); err != nil {
		return err
	}

	return nil
}

// GetJobTypeHandler creates a job type handler for the specified job type
func GetJobTypeHandler(jobType job_manager.JobType) (job_manager.JobTypeHandler, error) {
	switch jobType {
	case job_manager.JobTypeNotebook:
		return NewNotebookJobTypeHandler(), nil
	case job_manager.JobTypeTraining:
		return NewTrainingJobTypeHandler(), nil
	case job_manager.JobTypeBatch:
		return NewBatchJobTypeHandler(), nil
	default:
		return nil, job_manager.ErrUnsupportedJobType
	}
}
